<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'AddFlower.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->

</head>
<script type="text/javascript" src="statics/js/jquery-1.8.3.min.js"></script>

<body>
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<form  action="Book/addSave" method="post"  onsubmit="return validate()">
    <table border=1 style='text-align: center; margin: auto                                                '>
        <tr>
            <th style='font-size:35px;' colspan=2>添加图书</th>
        </tr>
        <tr>
            <th>图书名称：</th>
            <td><input type="text" name="bookName" value="" id="bookName" />
            </td>

        </tr>
        <tr>
            <th>图书作者：</th>
            <td><input type="text" name="bookAuthor" value="" id="bookAuthor" />
            </td>

        </tr>
        <tr>
            <th>出版社：</th>
            <td><input type="text" name="bookPublish" value="" id="bookPublish" />
            </td>

        </tr>
        <tr>
            <th>页数：</th>
            <td><input type="text" name="bookPage" value="" id="bookPage" />
            </td>
        </tr>
        <tr>
            <th>价格：</th>
            <td><input type="text" name="bookPrice" value="" id="bookPrice" />
            </td>

        </tr>
        <tr>
            <th>出版日期</th>
            <td><input type="text" name="bookPrice" value="" id="createDate" />
            </td>

        </tr>
        <tr>
            <td colspan=2><input type="submit" value="提交"><input
                    type="reset" value="重置">
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">


    function validate(){
        var ex = /^\d+$/;
        $("#bookName").parent().next().text("");
        $("#bookAuthor").parent().next().text("");
        $("#bookPublish").parent().next().text("");
        $("#bookPage").parent().next().text("");
        $("#bookPrice").parent().next().text("");
        if($("#bookName").val()==null||$("#bookName").val()==""){
            $("#bookName").parent().parent().append("<span style='color: red'>*此项不能为空</span>");
            return false;
        }else if($("#bookAuthor").val()==null||$("#bookAuthor").val()==""){
            $("#bookAuthor").parent().parent().append("<span style='color: red'>*此项不能为空</span>");
            return false;
        }else if($("#bookPublish").val()==null||$("#bookPublish").val()==""){
            $("#bookPublish").parent().parent().append("<span style='color: red'>*此项不能为空</span>");
            return false;
        }else if($("#bookPage").val()==null||$("#bookPage").val()==""){
            $("#bookPage").parent().parent().append("<span style='color: red'>*此项不能为空</span>");
            return false;
        }
        else if (!ex.test($("#bookPage").val())) {
            $("#bookPage").parent().parent().append("<span style='color: red'>*此项必须是整型类型</span>");
            return false;
        }  else if(isNaN($("#bookPrice").val())){
            $("#bookPrice").parent().parent().append("<span style='color: red'>*此项必须是数字类型</span>");
            return false;
        }
        else if($("#bookPrice").val()==null||$("#bookPrice").val()==""){
            $("#bookPrice").parent().parent().append("<span style='color: red'>*此项不能为空</span>");
            return false;
        }
        return true;
    }

</script>
</body>
</html>
